package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.SecurityUtils;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.CatTeamCategoryPrice;
import com.happy.cat.project.system.service.ICatTeamCategoryPriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 品类价格设置Controller
 *
 * @author verne
 * @date 2020-07-18
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/teamCategoryPrice" )
@Api("品类价格设置 API")
public class CatTeamCategoryPriceController extends BaseController {

    private final ICatTeamCategoryPriceService iCatTeamCategoryPriceService;

    /**
     * 查询品类价格设置列表
     */
    @ApiOperation(value = "查询品类价格设置列表",notes = "查询品类价格设置列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:teamCategoryPrice:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatTeamCategoryPrice catTeamCategoryPrice)
    {
        startPage();
        LambdaQueryWrapper<CatTeamCategoryPrice> lqw = new LambdaQueryWrapper<CatTeamCategoryPrice>();
        if (catTeamCategoryPrice.getItemId() != null){
            lqw.eq(CatTeamCategoryPrice::getItemId ,catTeamCategoryPrice.getItemId());
        }
        if (catTeamCategoryPrice.getType() != null){
            lqw.eq(CatTeamCategoryPrice::getType ,catTeamCategoryPrice.getType());
        }
        if (StringUtils.isNotBlank(catTeamCategoryPrice.getLevel())){
            lqw.eq(CatTeamCategoryPrice::getLevel ,catTeamCategoryPrice.getLevel());
        }
        if (catTeamCategoryPrice.getPrice() != null){
            lqw.eq(CatTeamCategoryPrice::getPrice ,catTeamCategoryPrice.getPrice());
        }
        if (catTeamCategoryPrice.getCreateDate() != null){
            lqw.eq(CatTeamCategoryPrice::getCreateDate ,catTeamCategoryPrice.getCreateDate());
        }
        if (catTeamCategoryPrice.getStatus() != null){
            lqw.eq(CatTeamCategoryPrice::getStatus ,catTeamCategoryPrice.getStatus());
        }
        List<CatTeamCategoryPrice> list = iCatTeamCategoryPriceService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出品类价格设置列表
     */
    @ApiOperation(value = "导出品类价格设置列表",notes = "导出品类价格设置列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:teamCategoryPrice:export')" )
    @Log(title = "品类价格设置" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatTeamCategoryPrice catTeamCategoryPrice) {
        LambdaQueryWrapper<CatTeamCategoryPrice> lqw = new LambdaQueryWrapper<CatTeamCategoryPrice>(catTeamCategoryPrice);
        List<CatTeamCategoryPrice> list = iCatTeamCategoryPriceService.list(lqw);
        ExcelUtil<CatTeamCategoryPrice> util = new ExcelUtil<CatTeamCategoryPrice>(CatTeamCategoryPrice. class);
        return util.exportExcel(list, "teamCategoryPrice" );
    }

    /**
     * 获取品类价格设置详细信息
     */
    @ApiOperation(value = "获取品类价格设置详细信息",notes = "获取品类价格设置详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:teamCategoryPrice:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCatTeamCategoryPriceService.getById(id));
    }

    /**
     * 新增品类价格设置
     */
    @ApiOperation(value = "新增品类价格设置",notes = "新增品类价格设置",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:teamCategoryPrice:add')" )
    @Log(title = "品类价格设置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatTeamCategoryPrice catTeamCategoryPrice) {
        catTeamCategoryPrice.setCreateDate(new Date());
        catTeamCategoryPrice.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatTeamCategoryPriceService.save(catTeamCategoryPrice) ? 1 : 0);
    }

    /**
     * 修改品类价格设置
     */
    @ApiOperation(value = "修改品类价格设置",notes = "修改品类价格设置",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:teamCategoryPrice:edit')" )
    @Log(title = "品类价格设置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatTeamCategoryPrice catTeamCategoryPrice) {
        catTeamCategoryPrice.setCreateDate(new Date());
        catTeamCategoryPrice.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatTeamCategoryPriceService.updateById(catTeamCategoryPrice) ? 1 : 0);
    }

    /**
     * 删除品类价格设置
     */
    @ApiOperation(value = "删除品类价格设置",notes = "删除品类价格设置",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:teamCategoryPrice:remove')" )
    @Log(title = "品类价格设置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iCatTeamCategoryPriceService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
